package cn.wolfcode.luowowo.redis.service.impl;

import cn.wolfcode.luowowo.redis.service.IUserRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

//用户缓存业务实现
@Service
public class UserRedisServiceImpl implements IUserRedisService {
    //注入操作redis数据库的bean(k,v都是String类型)
    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 缓存用户信息方法
     * @param key redis的key
     * @param value  redis的value
     * @param time     有效时间,单位秒
     */
    @Override
    public void cache(String key, String value, long time) {
        redisTemplate.opsForValue().set(key,value,time,TimeUnit.SECONDS);
    }
    //根据key获取rides中的信息
    @Override
    public String check(String key) {
        return  redisTemplate.opsForValue().get(key);
    }
    //重置缓存信息的过期时间
    @Override
    public void expire(String key, long time) {
        redisTemplate.expire(key,time,TimeUnit.SECONDS);
    }
}
